<script setup lang="ts">
//@ts-ignore
import CategoryStore from '@/store/modules/category';
import {onMounted} from "vue";
const categoryStore = CategoryStore();

defineProps(["scene"]);

onMounted(() => {
  categoryStore.getC1();
});

function handler1() {
  //清除二级分类和三级
  categoryStore.c2Id = '';
  categoryStore.c3Id = '';
  categoryStore.c2Arr.length = 0;
  categoryStore.c3Arr.length = 0;
  categoryStore.attrArr.length = 0;
  categoryStore.getC2();
}

function handler2() {
  //清空三级分类
  categoryStore.c3Id = '';
  categoryStore.c3Arr.length = 0;
  categoryStore.attrArr.length = 0;
  categoryStore.getC3();
}

</script>

<template>
  <el-card>
    <el-form inline>
      <el-form-item label="一级分类" style="width: 20%">
        <el-select v-model="categoryStore.c1Id" @change="handler1" :disabled="!!scene">
          <el-option v-for="(item) in categoryStore.c1Arr" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" style="width: 20%">
        <el-select v-model="categoryStore.c2Id" @change="handler2" :disabled="!categoryStore.c1Id || !!scene">
          <el-option v-for="(item) in categoryStore.c2Arr" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" style="width: 20%">
        <el-select v-model="categoryStore.c3Id" :disabled="!categoryStore.c2Id || !!scene">
          <el-option v-for="(item) in categoryStore.c3Arr" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<style scoped lang="scss">

</style>